package com.example.myapplication.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.example.myapplication.R;
import com.example.myapplication.bean.ImportBean;

import java.util.ArrayList;

public class ImportentDayAdapter extends ArrayAdapter<ImportBean> {
    private int resourceId;
    private Context context;
    private ArrayList<ImportBean> dataSet;

    public ImportentDayAdapter(@NonNull Context context, int resource, @NonNull ArrayList<ImportBean> objects) {
        super(context, resource,objects);
        this.context = context;
        this.resourceId = resource;
        this.dataSet = objects;
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        ImportentHolder importentHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(resourceId, null);
            importentHolder = new ImportentHolder();
            importentHolder.title = convertView.findViewById(R.id.til_txt);
            importentHolder.date = convertView.findViewById(R.id.date_txt);
            importentHolder.time = convertView.findViewById(R.id.time_txt);
            convertView.setTag(importentHolder);
        } else {
            importentHolder = (ImportentHolder) convertView.getTag();
        }
        final ImportBean importBean = dataSet.get(position);
        importentHolder.title.setText(importBean.getTitle_txt());
        importentHolder.date.setText(importBean.getYear()+"年"+importBean.getMonth()+"月"+importBean.getDay()+"日");
        importentHolder.time.setText(importBean.getHour()+"时"+importBean.getMin()+"分");

        return convertView;
    }

    public class ImportentHolder {
        TextView title;
        TextView date;
        TextView time;
    }
}
